#pragma once

class EntEarth : public EntBase 
{
public:
	//=== vars ===//
	irr::core::array<EntBase *>			m_apoEntColliding; // entities earth collided with
	irr::video::ITexture *				m_poTexDefaultCrater;	// default crater for selected level
	irr::video::ITexture *				m_poTexCurCrater;		// crater to use currently.. power ups may change this to larger crater
	irr::video::ITexture *				m_apoTexCraters[4];
	int									m_iDefautCraterIdx;
	irr::video::ITexture *				m_poTexContinents;		// continents color map

	int									m_iSizzelCnt;			// number of times comet went into water
	int									m_iImpactCnt;			// number of times comet impacted earth

	//=== constructor ===//
	EntEarth( VxIrrBase * poIrrBase, const EntSpawnData& oEntSpawnData );
	
	//=== methods ===//
	//! override EntBase
	//! load and apply textures from template
	virtual RCODE ApplyTextures( EntTemplate * poEntTemplate );

	//! override EntBase
	//! hande collision with another object
	//! return non zero if caller should not process any more contact points
	virtual RCODE HandleCollision( EntBase * poOtherEntity, const btPersistentManifold * poContactManifold, float f32NormalScale );
	//! override EntBase
	//! process before frame is rendered 
	virtual void	BeginFrame( void );
	//! override EntBase
	//! update
	virtual void	Update( U32 u32FrameTimeMs );
	//! override EntBase
	//! process after frame is rendered 
	virtual void	EndFrame( void );

	//! show crater etc and determine damage done by impact
	//! return percent was earth ( not water )
	int 	MakeImpactDamage( EntBase * poEntColliding, int& iRetTotalPixels, int& iRetPixelsDestroyed, BOOL bShowIntersectPointOnly = false );
	//! load image of crater to draw on earth when impacted
	RCODE	LoadCrater( void );
	//! returns the percent of earth considered destroyed
	float	GetPercentOfEarthDestroyed( void );

	//! blit image from one texture into another ( both textures must be 32bit format )
	//! return percent pixels changed
	int		DoCraterDamage(		int&					iRetTotalPixels,	// return total pixels in texture					
								int&					iRetPixelsDestroyed,// return number of pixels changed
								irr::video::ITexture *	poSrcTexture,		// texture to use as source image ( must be A8R8G8B8 fromat )
								U32						u32DestXPos,		// left pixel of destination image to blit to
								U32						u32DestYPos,		// top pixel of destination image to blit to
								irr::video::ITexture *	poDestTexture,		// texture to blit onto ( must be A8R8G8B8 fromat )
								BOOL					bWrap,				// if true then if blit goes past edge of destination image then wrap to other side
								U32						u33ExcludeLowColor, // if u33ExcludeLowColor != u33ExcludeHighColor then exclude copying to dest if
								U32						u33ExcludeHighColor );// color is not between u33ExcludeLowColor and u33ExcludeHighColor

	//! called once per second
	void		OncePerSecond( void );
	//! handle changes when power level goes up
	void		OnPowerLevelUp( S32 s32PowerLevel, S32 s32PowerUpTTL );
	//! handle changes when power level goes down
	void		OnPowerLevelDown( void );


};


